package org.linphone.sub.bean;

import java.util.ArrayList;

/**
 * Created by Xiang on 2018/5/15.
 */

public class SubConf {
	//分站一级矿名
	private String name;
	//分站组集合
	private ArrayList<SubgroupConf> subgrouplist;
	//实现单例
	private static SubConf mInstance = null;

	public static SubConf getmInstance(){
		if (mInstance == null) {
			synchronized (SubConf.class) {
				if (mInstance == null) {
					mInstance = new SubConf();
				}
			}
		}
		return mInstance;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public ArrayList<SubgroupConf> getSubgrouplist() {
		return subgrouplist;
	}

	public void setSubgrouplist(ArrayList<SubgroupConf> subgrouplist) {
		this.subgrouplist = subgrouplist;
	}

	//获取分站组号数组
	public ArrayList<String> getSubClassList(){
		ArrayList<String> as = new ArrayList<>();
		if(mInstance.getSubgrouplist()!=null){
			for(SubgroupConf sc: subgrouplist){
				as.add(sc.getNumber());
			}
		}
		return as;
	}

	@Override
	public String toString() {
		return "SubConf{" +
				"name='" + name + '\'' +
				", subgrouplist=" + subgrouplist +
				", mView=" + mView +
				'}';
	}



	//数据更新接口
	public interface IOnDataChange {
		void onChange(SubConf viewModel);
	}

	private IOnDataChange mView;
	//绑定View
	public void bind(IOnDataChange view) {
		mView = view;
		notifyDataSetChange();
	}

	public void unbind() {
		mView = null;
	}
	//更新数据
	public void notifyDataSetChange() {
		if (mView != null) {
			mView.onChange(this);
		}
	}

	public static class SubgroupConf{
		//分站组编号
		private String number;
		//此组的分站集合
		private ArrayList<SubListConf> sublist;

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public String getNumber() {
			return number;
		}

		public void setNumber(String number) {
			this.number = number;
		}

		public ArrayList<SubListConf> getSublist() {
			return sublist;
		}

		public void setSublist(ArrayList<SubListConf> sublist) {
			this.sublist = sublist;
		}

		//分站组名
		private String name;

		@Override
		public String toString() {
			return "SubgroupConf{" +
					"name='" + name + '\'' +
					", number='" + number + '\'' +
					", sublist=" + sublist +
					'}';
		}

		public static class SubListConf{
			//分站名称
			private String name;
			//分站IP信息
			private String ip;
			//分站状态
			private String states;
			//分站SIP号
			private int sip;

			public String getName() {
				return name;
			}

			public void setName(String name) {
				this.name = name;
			}

			public String getIp() {
				return ip;
			}

			public void setIp(String ip) {
				this.ip = ip;
			}

			public String getStates() {
				return states;
			}

			public void setStates(String states) {
				this.states = states;
			}

			public int getSip() {
				return sip;
			}

			public void setSip(int sip) {
				this.sip = sip;
			}

			@Override
			public String toString() {
				return "SubListConf{" +
						"name='" + name + '\'' +
						", ip='" + ip + '\'' +
						", states='" + states + '\'' +
						", sip=" + sip +
						'}';
			}
		}
	}

}
